<?php
	include 'connection.php';
	include 'header.php';
	
	header('Content-type: text/json');
	
	$query 	= "SELECT * FROM event";
	$result = mysql_query($query, $link);
	
	//echo $result;
	echo '[';
	
	if(mysql_num_rows($result) > 0) {
		
		$jml_row	= mysql_num_rows($result);
		
		for ($x=1; $x <= $jml_row; $x++) {
			$event 	= mysql_fetch_array($result);
		
			//$JSON	= json_encode($pre);
			//$event	= json_decode($JSON);
			
			if ($x == $jml_row) {
				echo '  { "date": "'.$event["time_start"].'", "type": "event", "title": "'.$event["title"].'", "description": "", "url": "event.php?id='.$event["event_id"].'" }';
			} else {
				echo '  { "date": "'.$event["time_start"].'", "type": "event", "title": "'.$event["title"].'", "description": "", "url": "event.php?id='.$event["event_id"].'" },';
			}
		}
	}
	
	echo ']';
	/*
	echo '[';

	foreach ($result as $event) {
		echo ' { "date": "'.$event["time_start"].'", "type": "event", "title": "'.$event["title"].'", "description": "'.$event["description"].'", "url": "'.$event["web"].'" },';
	}
	
	echo '  { "date": "2014-02-02 17:30:00", "type": "meeting", "title": "Test Last Year", "description": "Lorem Ipsum dolor set", "url": "" },';
	echo '  { "date": "2014-03-23 17:30:00", "type": "meeting", "title": "Test Next Year", "description": "Lorem Ipsum dolor set", "url": "http://www.event3.com/" }'; 

	echo ']'; // */
?>